var e = require("../../@babel/runtime/helpers/interopRequireDefault"), r = e(require("../../@babel/runtime/regenerator")), a = require("../../@babel/runtime/helpers/asyncToGenerator"), t = e(require("../../utils/api"));

getApp();

Page({
    data: {
        clicked: !1,
        form: {
            username: "",
            phone: "",
            companyName: "",
            companyId: "",
            authCode: "",
            isParty: 0,
            partyBranchId: ""
        }
    },
    onLoad: function(e) {
        this.setData({
            form: JSON.parse(e.param)
        });
    },
    onShow: function() {},
    getUserInfo: function() {
        var e = this;
        return a(r.default.mark(function n() {
            return r.default.wrap(function(n) {
                for (;;) switch (n.prev = n.next) {
                  case 0:
                    if (!e.data.clicked) {
                        n.next = 2;
                        break;
                    }
                    return n.abrupt("return");

                  case 2:
                    e.setData({
                        clicked: !0
                    }), wx.getUserProfile({
                        desc: "业务需要",
                        success: function() {
                            var n = a(r.default.mark(function n(o) {
                                return r.default.wrap(function(n) {
                                    for (;;) switch (n.prev = n.next) {
                                      case 0:
                                        wx.login({
                                            success: function() {
                                                var n = a(r.default.mark(function a(n) {
                                                    var c, u;
                                                    return r.default.wrap(function(r) {
                                                        for (;;) switch (r.prev = r.next) {
                                                          case 0:
                                                            return r.prev = 0, c = {
                                                                code: n.code,
                                                                name: e.data.form.username.trim(),
                                                                phone: e.data.form.phone,
                                                                nickName: o.userInfo.nickName,
                                                                headImg: o.userInfo.avatarUrl,
                                                                city: o.userInfo.city,
                                                                province: o.userInfo.province,
                                                                companyId: parseFloat(e.data.form.companyId),
                                                                authCode: e.data.form.authCode
                                                            }, 7 == e.data.form.companyId && (c.isParty = e.data.form.isParty, 1 == e.data.form.isParty && e.data.form.partyBranchId && (c.partyBranchId = e.data.form.partyBranchId)), 
                                                            r.next = 5, t.default.login(c);

                                                          case 5:
                                                            if ((u = r.sent).result.openid) {
                                                                r.next = 9;
                                                                break;
                                                            }
                                                            return wx.navigateTo({
                                                                url: "/pages/login/login"
                                                            }), r.abrupt("return");

                                                          case 9:
                                                            wx.setStorageSync("openid", u.result.openid), wx.switchTab({
                                                                url: "/pages/index/index"
                                                            }), r.next = 16;
                                                            break;

                                                          case 13:
                                                            r.prev = 13, r.t0 = r.catch(0), console.log(r.t0);

                                                          case 16:
                                                          case "end":
                                                            return r.stop();
                                                        }
                                                    }, a, null, [ [ 0, 13 ] ]);
                                                }));
                                                return function(e) {
                                                    return n.apply(this, arguments);
                                                };
                                            }()
                                        });

                                      case 1:
                                      case "end":
                                        return n.stop();
                                    }
                                }, n);
                            }));
                            return function(e) {
                                return n.apply(this, arguments);
                            };
                        }(),
                        fail: function(e) {
                            console.log(e);
                        }
                    });

                  case 4:
                  case "end":
                    return n.stop();
                }
            }, n);
        }))();
    }
});